package com.suncaper.han_yi_system.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

@RestController
@Tag(name = "AI接口")
public class AIController {

    @Autowired
    private ChatClient chatClient;

    @GetMapping("/chat/v1")
    @Operation(summary = "聊天调用")
    public String ollamaChat(String msg, String chatId) {
        return chatClient.prompt().user(msg)
                .advisors(a->a.param(ChatMemory.CONVERSATION_ID, chatId))
                .call().content();
    }

    @GetMapping("/chat/v2")
    @Operation(summary = "流式聊天调用")
    public Flux<String> ollamaChat2(String msg, String chatId) {

        Flux<String> stream = chatClient.prompt().user(msg)
                .advisors(a->a.param(ChatMemory.CONVERSATION_ID, chatId))
                .stream().content();
        return stream;
    }

}
